#ifndef AST_POSTFIX_EXPR_H
#define AST_POSTFIX_EXPR_H

#include "../ASTNode.h"

class sym;
class PrimaryExpr;
class Expression;
class ArgumentExprList;
class InitializerList;
class TypeName;
/*
C99 6.5.2
postfix-expression:
		primary-expression
		postfix-expression  [  expression  ]
		postfix-expression (  argument-expression-list(opt)  )
		postfix-expression  .  identifier
		postfix-expression ->  identifier
		postfix-expression  ++
		postfix-expression  --
		(  type-name  )  {  initializer-list  }
		(  type-name  )  {  initializer-list, }
*/
class PostfixExpr : public ASTNode
{
public:
	enum {
		primary_expression,
		arry_expression,
		function_call_with_argument,
		function_call_no_argument,
		point_expression,
		arrow_expression,
		plus_expression,
		sub_expression,
		type_initial_expression,
	};
protected:
	PostfixExpr(void)
		: ASTNode(ASTNode::postfix_expression){};
public:
	PostfixExpr(PrimaryExpr *	pPrimaryExpr)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(primary_expression)
		, m_pPrimaryExpr(pPrimaryExpr){};

	PostfixExpr(PostfixExpr *pPostExpr, Expression * pExpr)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(arry_expression)
		, m_pPostfixExpr(pPostExpr)
		, m_pArryExpr(pExpr){};
	PostfixExpr(PostfixExpr *pPostExpr, ArgumentExprList *pArguments)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(function_call_with_argument)
		, m_pPostfixExpr(pPostExpr)
		, m_pArguments(pArguments){};

	PostfixExpr(PostfixExpr *pPostExpr, int iType)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(iType)
		, m_pPostfixExpr(pPostExpr){};
	PostfixExpr(PostfixExpr *pPostExpr, sym *pId, int iType)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(iType)
		, m_pPostfixExpr(pPostExpr)
		, m_pIdentifier(pId){};

	PostfixExpr(TypeName *pTypeName, InitializerList *pInitializer)
		: ASTNode(ASTNode::postfix_expression)
		, m_iType(type_initial_expression)
		, m_pType(pTypeName)
		, m_pInitializer(pInitializer){};

	virtual ~PostfixExpr(void);

	virtual void				codeGen();
protected:
	tiny_int				m_iType;
	union{
		PrimaryExpr *				m_pPrimaryExpr;
		struct{
			PostfixExpr *			m_pPostfixExpr;
			union{
				Expression *			m_pArryExpr;
				ArgumentExprList *		m_pArguments;
				sym *					m_pIdentifier;
			};
		};
		struct {
			TypeName *					m_pType;
			InitializerList *		m_pInitializer;
		};
	};
};


#endif


